<template>
  <el-row class="tac">
    <el-col :span="24">
      <el-menu
        active-text-color="#ff8c00"
        background-color="#fff"
        class="el-menu-vertical-demo"
        :default-active="activeIndex"
        text-color="#333"
        router
        @open="handleOpen"
        @close="handleClose"
      > 
        <el-menu-item index="/diancai">
          <el-icon><Menu /></el-icon>
          <span>菜单</span>
        </el-menu-item>
        <el-menu-item index="/cart">
          <el-icon><ShoppingCart /></el-icon>
          <span>购物车</span>
        </el-menu-item>
        <el-sub-menu index="1">
          <template #title>
            <el-icon><DataAnalysis /></el-icon>
            <span>统计表</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/report">销售统计</el-menu-item>
            <el-menu-item index="/report1">菜品分析</el-menu-item>
          </el-menu-item-group>
        </el-sub-menu>
        <el-menu-item index="/user-profile">
          <el-icon><User /></el-icon>
          <span>个人信息</span>
        </el-menu-item>
      </el-menu>
    </el-col>
  </el-row>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import {
  Menu,
  ShoppingCart,
  DataAnalysis,
  User
} from '@element-plus/icons-vue'

const route = useRoute()
const activeIndex = ref('/diancai')

onMounted(() => {
  // 根据当前路由设置活动菜单项
  activeIndex.value = route.path
})

const handleOpen = (key, keyPath) => {
  console.log(key, keyPath)
}

const handleClose = (key, keyPath) => {
  console.log(key, keyPath)
}
</script>

<style scoped>
.el-menu-vertical-demo {
  border-right: none;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.el-menu-item,
.el-sub-menu__title {
  transition: background-color 0.3s ease;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background-color: #fff6e6;
}

.el-menu-item.is-active {
  background-color: #fff6e6;
  border-right: 3px solid #ff8c00;
}
</style>